<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : commonframework.core.php   FILE_PATH : \\classes\core\commonframework.core.php
 * 框架类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Tue Aug 07 12:46:33 CST 2007
 */

class FrameWork extends UIPage{
	/**
	 * 语言包
	 *
	 * @var var[]
	 */
	var $_lang = array();
	/**
	 * 数组设置文件，已转为相应的语言
	 *
	 * @var var[]
	 */
	var $_b_config = array();
	/**
	 * 语言包类型
	 *
	 * @var string
	 */
	var $_langType='zh-cn';

	/**
	 * 初始化框架类
	 *
	 * @return CommonFrameWork
	 */

	function setFrameWork($errorlevel="",$contenttype=""){
		/**
		 * 设置错误响应级别
		 */
		if ($errorlevel != "")
		$this->_errorlevel = $errorlevel;

		/**
		 * 设置页面类型
		 */
		if ($contenttype != ""){
			$this->_contenttype = $contenttype;
		}
		/**
		 * 初始化系统基本初始化类
		 */
		$this->_initialize();
		/**
		 * 初始化数据库操作类
		 */
		$this->_dbinitialize();
		/**
		 * 初始化页面显示类
		 */
		$this->_uiinitialize();
		/**
		 * 设置数组信息
		 */
		require("baseconfig.inc.php");
		$this->_b_config = $b_config;

		/**
		 * 默认输出值
		 */
		$this->output("refer_url",urlencode($this->refer_url));    //输出上一页URL地址
		$this->output('coo_back',$this->cookie_back_form);     //输出上一页提交的表单信息
		$this->output($this->_configinfo['websit']);
		$this->output('ifhtml',$this->_configinfo['productinfo']['ifhtml']);//产品静态页标识
	}

	/**
	 * 初始化数据库操作类
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array/string
	 */
	function _dbinitialize(){
		if (!is_object($GLOBALS['db'])){
			/**
			 * 引入数据库操作引擎
			 */
			if (file_exists(BasePath . "/classes/core/" . $this->_configinfo['database']['engine_type'] . ".core.php")){
				include_once($this->_configinfo['database']['engine_type'] . ".core.php");
				require_once(BasePath."/classes/core/database.core.php");
				$GLOBALS['db'] = new DataBase();
				define('NC_DBTABLEPRE',$this->_configinfo['database']['dbprefix']);
			}else{
				echo "装载数据引擎失败";exit;
			}
		}
	}
	
	/**
	 * 得到语言包
	 *
	 * @param string $langlist
	 */
	function getlang($langlist){
		//缓存类初始化
		$this->_getObjCache();
		
		$langlist = $langlist;
		$lang = array();
		$langarray = explode(",",$langlist);
		foreach ($langarray as $v){
			$langType = $this->_langType;
			if ($langType == "") {
				$this->obj_ini_cache->lang_versionarea = $this->_configinfo['websit']['versionarea'];
			}
			else
			{
				$this->obj_ini_cache->lang_versionarea = $langType;
			}

			$this->obj_ini_cache->web_config = $this->_configinfo['websit'];
			$this->obj_ini_cache->OperateCacheFile($v,"lang",$this->_configinfo['websit']['ncharset']);
			$lang = $this->obj_ini_cache->cache_array;

			if (is_array($lang) && is_array($this->_lang)){
				$this->_lang = array_merge($lang,$this->_lang);
			}else{
				$this->_lang = $lang;
			}
		}


		/**
		 * 把数组设置信息替换为响应的语言
		 */
		$this->_b_config = $this->_getconfigvalue();
		/**
		 * 判断模板是否被初始化
		 */
		if (!is_object($this->_objsmarty)){
			$this->_uiinitialize();
		}
		$this->output($this->_lang);
	}


	/**
	 * 得到程序设置信息的值，把值转换为相应的语言
	 *
	 */
	function _getconfigvalue(){
		if (is_array($this->_b_config)){
			$param = $this->_b_config;
			foreach($param as $key => $array){
				foreach($array as $k=>$v){
					if ($this->_lang[$v] != ""){
						$param[$key][$k] = $this->_lang[$v];
					}
				}
			}
		}
		return $param;
	}

	/**
	 * 跳转到某个页面
	 *
	 * @param string $genre  类型 common一般跳转 error跳转到错误页面 refer上一个页面
	 * @param string $path
	 * @param string $message
	 * @param string $page_type  跳转页面类型，0为前台，1为后台
	 */
	function redirectPath($genre="common",$path="",$message="",$page_type="0"){

		if ($path == ""){
			$path = urldecode($this->refer_url);   //上一页面路径
			$flag = 1;
		}else{
			$path = urldecode($path);
		}
		//$this->setCookies('sys_sid',$this->session_id,"");
		if ($page_type == "0"){
			$pagename = "home";//member
		}else{
			$pagename = $this->_configinfo['websit']['systemadmin'];
		}
		$message = urlencode($message);  //页面上所显示的信息
		//echo $path;exit;
		if ($genre == "common"){
			@header("Location:" . $this->_configinfo['websit']['site_url'] . "/" . $path);
		}else if ($genre == "error"){
			@header("Location:" . $this->_configinfo['websit']['site_url'] . "/" . $pagename . "/error.php?message=" . urlencode($message) . "&backurl=" . urlencode($path));
		}else if($genre == "refer"){
			@header("Location:" . $path);
		}else if($genre == "succ"){
			if ($flag == 1){
				$substr = "?backurl=" . urlencode($path) . "&message=" . urlencode($message);
			}
			else{
				$substr = "?backurl=" . urlencode($this->_configinfo['websit']['site_url'] . "/" . $path) . "&message=" . urlencode($message);
			}
			@header("Location: " . $this->_configinfo['websit']['site_url'] . "/"  . $pagename . "/error.php" . $substr);			
		}
		exit;
	}
	
	/**
	 * 保持会员登录的链接状态
	 */
	function _update_login_state(){
//		if ($_SESSION['login_token'] == $_COOKIE['c_login_token'] && $_SESSION['s_login']['login'] == '1'){
		if ($_SESSION['s_login']['login'] == '1'){
			setcookie("c_login_name",$_SESSION["s_login"]['name'],time()+$this->cookie_expire_time,'/',$this->_configinfo['cookie']['cookiedomain']);
			setcookie("c_session_id",session_id(),time()+$this->cookie_expire_time,'/',$this->_configinfo['cookie']['cookiedomain']);
		}
			
//			$this->_set_login_token();
			return true;
//		}else {
//			unset($_COOKIE);
//			unset($_SESSION);
//			return false;
//		}
	}
	/**
	 * 对cookie和session进行验证令牌赋值
	 */
	function _set_login_token(){
		//加密令牌
//		$login_token = Common::mycrpyt(rand(10000,99999));
//		setcookie("c_login_token",$login_token,time()+$this->cookie_expire_time,'/',$this->_configinfo['cookie']['cookiedomain']);
//		$_SESSION['login_token'] = $login_token;
		return true;
	}
}
?>